{% extends "base.html" %}

{% block content %}
<script type="text/javascript" src="/static/js/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="/static/js/jquery.cookie.min.js"></script>
<script type="text/javascript" src="/static/js/artDialog/jquery.artDialog.js?skin=default"></script>
<script type="text/javascript" src="/static/js/artDialog/plugins/iframeTools.js"></script>
<script type="text/javascript" src="/medias/ckeditor/static/editor/editor/filemanager/browser/default/js/fckxml.js"></script>
<style>
.base{
	width:1000px;
	padding:5px;
	margin:5px;
	line-height:30px;
}
.base .filelist{
	width:200px;
	overflow-y:auto;
}
.base .filecon{
	width:760px;
	min-height:300px;
}
.filecontent:hover{
	background:#def;
}
.left{
	float:left;
	margin:5px;
	padding:4px;
	border:1px solid #def;
}
tr{
	cursor:pointer;
}
.emaillist{
	padding:3px;
	overflow:auto;
	word-break:break-all;
}
.emaillist:hover{
	background:#efefef;
	cursor:pointer;
}
.loading{
	width: 50px;
	height: 50px;
	margin: auto;
	text-align: center;
	line-height: 150px;
	margin-top:100px;
}
.loading img{
	width:20px;
	height:20px;
}
.info{
	color:#6D5A5A;
}
.error{
	color:#A50707;
}
</style>
<div class="base">
	<div class="left filelist">
		<table width="100%" class="aui-ibox-data aui-dotted-split">
			<tr>
				<th>log文件列表</th>
			</tr>
		</table>
	</div>
	<div class="left filecon">
	</div>
</div>
<script>
	var oxml = new FCKXml
	function getFiles(filepath,obj){
		oxml.LoadUrl('/fck/getimages/?fp=/static/log&c=GetFiles&t='+filepath,function(e){
			$(obj).children('td').find('ul.files').empty()
			var oNodes = e.SelectNodes('Connector/Files/File')
			for ( var j = 0 ; j < oNodes.length ; j++ ){
				var oNode = oNodes[j] ;
				var sFileName = oNode.attributes.getNamedItem('name').value ;
				var sFolderName = oNode.attributes.getNamedItem('floader').value ;
				$(obj).children('td').find('ul.files').prepend('<li class="filecontent" onclick="getFileCon(this,event);return false;" abcpath="/static/log'+sFolderName+sFileName+'"><img alt="adf" src="/medias/ckeditor/static/editor/editor/filemanager/browser/default/images/icons/txt.gif" width="16" height="16" border="0">'+sFileName+'</li>')
			}
		})
	}
	function ChangeFolder(obj){
		$('.folder').children('img').attr('src','/medias/ckeditor/static/editor/editor/filemanager/browser/default/images/Folder.gif')
		$('.folder').find('.files').hide()
		$(obj).find('img').attr('src','/medias/ckeditor/static/editor/editor/filemanager/browser/default/images/FolderOpened.gif')
		$(obj).find('.files').show()
	}
	function getFileCon(obj,evt){
		if (window.event) {  
			event.cancelBubble = true;  
		}else{
			evt.stopPropagation();
		}
		var filename = $(obj).attr('abcpath')
		if(filename == ''){
			art.dialog.alert('系统错误');
			return;
		}
		$('div.filecon').empty()
		$('div.filecon').append('<div class="loading"><img src="/static/images/loading.gif"></div>');
		var path = $(obj).attr('abcpath')
		$.get(path+'?'+Math.random(),function(e,code){
			$('div.filecon').empty()
			var data = e.split('\n')
			var html = ''
			var temp = ''
			var bgcolor = ''
			var colors = ['EDDDEE','E9F9EE','EFD6BB','B3D187','BBE0E2','AFF1F5','BFDDDF','EFDBCA','ABCDEF','FeDDef']
			if(data[0]!=''){
				for(var i=0,j=0;i<data.length;i++){
					var margin = 0
					var d = data[i].slice(1,6)
					if(d.indexOf('-')!=-1){
						d = data[i].slice(1,20)
					}
					if(temp != d && d!=''){
						if(j>=colors.length){j=0}
						bgcolor = '#'+colors[j++]
						temp = d
						margin = 2
					}
					if(data[i]=='')continue;
					var fontcolor = ''
					if(/ERROR/.test(data[i])){fontcolor='error'}
					if(/INFO/.test(data[i])){fontcolor='info'}
					html = '<div class="emaillist '+fontcolor+'" id="show_'+i+'" style="background:'+bgcolor+';margin-bottom:'+margin+'px;">'+data[i]+'</div>'
					$('div.filecon').prepend(html)
				}
			}else{
				html = '<div class="emaillist" style="background:#'+colors[Math.floor(Math.random()*10)]+'">No Log Info!</div>'
				$('div.filecon').prepend(html)
			}
		})
	}
(function(){
	function getFilelist(){
		oxml.LoadUrl('/fck/getimages/?fp=/static/log&c=GetFoldersAndFiles',function(e){
			var data = e.SelectNodes('Connector/Folders/Folder')
			for ( var i = 0 ; i < data.length ; i++ ){
				var sFolderName = data[i].attributes.getNamedItem('name').value ;
				var t = data[i].attributes.getNamedItem('true').value ;
				$('.filelist table').append('<tr onclick="getFiles(\''+t+'\',this);ChangeFolder(this);"><td class="folder"><img alt="" src="/medias/ckeditor/static/editor/editor/filemanager/browser/default/images/Folder.gif" width="16" height="16" border="0">'+sFolderName+'<ul class="files" style="display:none;margin: 5px 0 0 25px;line-height:25px;"></ul></td></tr>')
			}
		})
	}
	getFilelist();
})();
</script>
{% endblock %}